package com.baizhi.controller;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.service.CmfzUserService;
import com.baizhi.service.UserThreadServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("user")
public class CmfzUserController {
    @Autowired
    private CmfzUserService cmfzUserService;
    @Autowired
    private UserThreadServcie userThreadServcie;
    /**
     * [12,23]
     *
     * [{
     *     name :
     *     value :
     * },{
     *
     * }]
     * @return
     */
    @RequestMapping("getSexCount")
    public List<Map> getSexCount(){
        return cmfzUserService.selectBySexCount();
    }

    @RequestMapping("getByProvince")
    public List<Map> getByProvince(){
        return cmfzUserService.selectByProvince();
    }

    @RequestMapping("getByDayCount")
    public Map getByDayCount(){
        return cmfzUserService.selectByDayCount();
    }

    /**
     *  优化
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("selectAllCountThread")
    public Map selectAllCountThread() throws Exception {
        long start = System.currentTimeMillis();

        Map map = cmfzUserService.selectByThread();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms");
        return map;
    }
    /**
     * 无优化
     * @return
     */
    @RequestMapping("selectAllCount")
    public Map selectAllCount() throws InterruptedException {
        long start = System.currentTimeMillis();
        Map map = userThreadServcie.selectAllCount();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms");
        return map;
    }
}
